home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 173 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: dawn.mmm.com!news
  2. From: kjhopps@mmm.com (Kevin J Hopps)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ compilers
  5. Date: 2 Jan 1996 14:07:34 GMT
  6. Organization: 3M - St. Paul, MN  55144-1000 US
  7. Message-ID: <4cbe76$kst@dawn.mmm.com>
  8. References: <4bajl8$fsh@castle.nando.net> <kshadowe.123.00143C15@iamerica.net> <4bs061$hh3@nntpa.cb.att.com>
  9. Reply-To: kjhopps@mmm.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. -D.OBrien (dob@cbsky.cb.att.com) wrote:
  13. > In article <kshadowe.123.00143C15@iamerica.net>,
  14. >  <kshadowe@iamerica.net> wrote:
  15. > >In article <4bajl8$fsh@castle.nando.net> nhawk <nhawk@mailhost.nando.net> writes:
  16. > >
  17. > >
  18. > >>Hello All,
  19. > >
  20. > >>I am a beginner learning to program in C++. I have Borland's Turbo C++ 
  21. > >>for DOS and Turbo C++ Visual edition, AT&T C++ 2.? and GNU C++ 2.7.0. 
  22. > >>Only the latter, in my experience, supports Boolean types. What other C++ 
  23. > >>compilers currently support Boolean types? How about Watcom C++? Any help 
  24. > >>will be appreciated.
  25. > >
  26. > > How about to write
  27. > >
  28. > >  #define FALSE 0
  29. > >  #define TRUE 1
  30. > >  enum BOOLEAN {FALSE,TRUE};
  31.  
  32. > How about just:
  33.  
  34. >     enum BOOLEAN {FALSE, TRUE};
  35.  
  36. My approach would be to define things so as to minimize the impact when my
  37. compiler supported the new keywords.  This means that my solution would
  38. have to use "bool" as the type name, and "true" and "false" as values
  39. for the type "bool."
  40.  
  41. Now, depending on whether I want to distinguish between bool and other
  42. built in types (perhaps for overloading purposes) or whether I want
  43. automatic conversion between int and bool, I would use an enum or a
  44. typedef.  I happen to not care about overloading, so I have taken this
  45. approach:
  46.     #ifndef HAVE_BUILTIN_BOOL
  47.     typedef int bool;
  48.     const bool true = 1;
  49.     const bool false = 0;
  50.     #endif
  51.  
  52. When my compiler supports the bool type, I will turn this code off.
  53. --
  54. Kevin J. Hopps                  e-mail: kjhopps@mmm.com
  55. 3M Company                      phone:  (612) 737-4643
  56. 3M Center, Bldg. 235-2D-57      fax:    (612) 737-2700
  57. St. Paul, MN 55144-1000         Opinions are my own.  I don't speak for 3M.
  58.     But 3M speaks for me -- I did not write the following line:
  59.  
  60. Opinions expressed herein are my own and may not represent those of 3M.
  61.